package com.open.lua;


import org.keplerproject.luajava.JavaFunction;
import org.keplerproject.luajava.LuaException;
import org.keplerproject.luajava.LuaState;

public class LoadLibExample {
	/**
	 * Lua脚本使用LoadLib回调Java,并传多个参数
	 * @param L
	 * @return
	 * @throws LuaException
	 */
	public static int open(LuaState L) throws LuaException {
		L.newTable();  //新建表
		L.pushValue(-1); //将表压入栈顶
		L.setGlobal("javaObjcet");  //设置为全局变量 

		L.pushString("methodOpen");  //压入字符串到栈顶

		L.pushJavaFunction(new JavaFunction(L) {  //压入函数到栈顶

			public int execute() throws LuaException {

				for (int i = 0, count = L.getTop() + 1; i < count; ++i) {
					System.out.println(getParam(i));
				}
				return 0;
			}
		});

		L.setTable(-3);

		return 1;
	}
}

